<%@ page language="java" import="java.util.*,java.sql.*,com.util.info" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <style type="text/css"> 
<!-- 
a:link { 
font-size: 14px; 
color: #000000; 
text-decoration: none; 
} 
a:visited { 
font-size: 14px; 
color: #000000; 
text-decoration: none; 
} 
a:hover { 
font-size: 14px; 
color: #999999; 
text-decoration: underline; 
} 
--> 
</style>
    <title>公告与通知</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  
  </head>
  
  <body>
  <script language=javascript>
function show(no)
{
for(var i=1;i<20;i++)
{
var a = document.getElementById(no+"@"+i);
if(a==null)
{
continue;
}
if(a.style.display=="")
{
a.style.display="none";
}else{
a.style.display="";
}
}

}
</script>
  <script language="javascript">
window.onload() { 
       window.parent.change("会议与通知");
} 
</script>
   <%
//定义四个分页会用到的变量
int pageSize=3;
int pageNow=1;//默认显示第一页
int rowCount=0;//该值从数据库中查询
int pageCount=0;//该值是通过pageSize和rowCount
//接受用户希望显示的页数（pageNow）
String key = request.getParameter("key")==null?"":request.getParameter("key");
String f = request.getParameter("f");
String s_pageNow=request.getParameter("pageNow");
if(s_pageNow!=null){
//接收到了pageNow
pageNow=Integer.parseInt(s_pageNow);
}
//查询得到rowCount
Class.forName("com.mysql.jdbc.Driver").newInstance(); 
String url="jdbc:mysql://localhost:3306/graduatedesign";  
String user="root";  
String password="root";  
Connection conn = DriverManager.getConnection(url, user, password); 
Statement sm=conn.createStatement();
String sql="select count(*) from notices ";
String hql="select id,title,type,date from notices ";
if(f!=null)
         {
         key = info.getUTFStr(key);
         }
         if(!key.equals(""))
         {
         sql+="where title like'%"+key+"%' ";
         hql+="where title like'%"+key+"%' ";
         }
ResultSet rs=sm.executeQuery(sql);
if(rs.next()){
rowCount=rs.getInt(1);
}
//计算pageCount
if(rowCount%pageSize==0){
pageCount=rowCount/pageSize;
}else{
pageCount=rowCount/pageSize+1;
}
//查询出需要显示的记录
rs=sm.executeQuery(hql+" order by date desc limit " + (pageNow-1)*pageSize+","+pageSize);
%>
<form id="form1" name="form1" method="post" action="admin/notice.jsp?f=f">
						<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#BBD3EB">
                          <tr>
                            <td height="26" align="center" bgcolor="#FFFFFF">请输入相关信息</td>
                            <td height="26" align="left" bgcolor="#FFFFFF">
                              <label>
                                &nbsp;<input name="key" type="text" value="<%=key %>" id="textfield" size="40" />&nbsp;
                                <input type="submit" name="button" id="button" value="查询" />
                              </label>                                                    </td>
                          </tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#BBD3EB">
                          <tr>
                          <td height="27" align="center" background="/OA/admin/images/index1_72.gif" bgcolor="#FFFFFF">ID</td>
                            <td height="27" align="center" background="/OA/admin/images/index1_72.gif" bgcolor="#FFFFFF">标题</td>
                            <td height="27" align="center" background="/OA/admin/images/index1_72.gif" bgcolor="#FFFFFF">类型</td>
                            <td align="center" background="/OA/admin/images/index1_72.gif" bgcolor="#FFFFFF">添加日期</td>
    </tr>
<%
while(rs.next()){
%>
<tr>
                            <td height="26" align="center" bgcolor="#FFFFFF"><%=rs.getInt(1)%></td>
                            <td height="26" align="center" bgcolor="#FFFFFF"><a href="admin/noticeview.jsp?Id=<%=rs.getInt(1) %>"><%=rs.getString(2) %></a></td>
                            <td height="26" align="center" bgcolor="#FFFFFF"><%=rs.getString(3)%></td>
                            <td height="26" align="center" bgcolor="#FFFFFF"><%=rs.getString(4)%></td>
                          </tr>
<%}%>
<tr>
<td height="26" colspan="10" align="center" bgcolor="#FFFFFF"><font color='#1157B7'><%
//上一页
if(pageNow!=1){
out.println("<a href=admin/notice.jsp?f=f&key="+key+"&pageNow="+(pageNow-1)+">上一页</a>");
}
//显示超链接
for(int i=1;i<=pageCount;i++){
out.println("<a href=admin/notice.jsp?f=f&key="+key+"&pageNow="+i+">["+i+"]</a>");
}
//下一页
if(pageNow!=pageCount){
out.println("<a href=admin/notice.jsp?f=f&key="+key+"&pageNow="+(pageNow+1)+">下一页</a>");
}
%></td>
                         
                          </tr>
</table>
</form>  
  </body>
</html>
